<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>选择会员卡</title>
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" name="viewport">
	<script src="js/flexible.js"></script>
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/homePage.css">
	<link rel="stylesheet" href="css/flexible.css">
	<link rel="stylesheet" href="css/vant.css">
	<script src="js/jquery-3.3.1.min.js"></script>
	<script src="js/vue/vue.js"></script>
	<script src="js/vue/axios.js"></script>
	<script src="js/vue/MD5.js"></script>
	<script src="js/vue/vant.js"></script>
	<script src="js/vue/qs.js"></script>
</head>
<body>
<div id="app">
	<div class="under_line"></div>
	<template>
		<div class="member_card">
			<p  class="member_card_title">会员卡</p>
			<div class="year_card_list clearfix"  v-for="(item,index) in cardList">
				<div class="entrance_sign fl">
					<p class="entrance_sign_txt">{{item.Cardname}}</p>
					<p class="entrance_sign_date">{{item.time}}</p>
					<p class="entrance_sign_in"><span>{{item.account}}</span></p>
				</div>
				<div class="remaining_day fr">
					<div class="remaining_day_txt"><span>{{item.Surplus_str}}</span></div>
					<div style="margin-top: 0.18rem;text-align: center;"
						v-if="item.is_yy=='0'" @click="selected(index,item.id,item.Csid)">
						<img v-if="currIndex==index" src="images/check_in.png">
						<img v-else src="images/check_not.png" alt="" class="check_in">
					</div>
				</div>
			</div>
			<div class="notDate" v-else style="margin-top: .3rem;text-align: center;">
				<img src="images/notDate.jpg"/>
			</div>
			<div class="appointment_btn" @click="order">预约</div>
		</div>	
	</template>
</div>
<div class="technology">馆家提供技术支持</div>
</body>
<script>
var vm=new Vue({
    el: '#app',
    data: {
		vid:'',
        moren:'images/moren.png',
		cardList:[],
		currIndex:'0',
		from:{
			uid:'',
			plan_id:'',
			key:'',
			date:'',
			currid:'',
			stime: '',
			etime: '',
			cid: '',
			csid: '',
		}
    },
    created(){
        this.setCanS()
    },
    methods:{
		 //设置参数
		 setCanS(){
            let Request = new Object()
            Request = GetRequest()
            this.from.uid = Request['uid']
			this.from.plan_id = Request['plan_id']
			this.from.key = Request['key']
			this.from.date = Request['date']
			this.from.currid = Request['currid']
            this.getList()
        },
        getList() {
			this.vid=sessionStorage.getItem('vids')
			const params=this.from
			getVs()
			axios.get('/mobileapi/coach/curr.php?act=tk_yy_list',{params:params}).then(data =>{
				console.log(data.data)
				let { msg, code,user} = data.data
					if (code !== 200) {
						window.vant.Toast.fail(msg);
					} else {
						data=data.data
						this.cardList=data.data.card_list
						this.from.stime=data.data.kc_info.Stime
						this.from.etime=data.data.kc_info.Etime
						//设置默认选择一张卡
						for(let i in this.cardList){
							if(this.cardList[i].is_yy=='0'){
								this.from.cid=this.cardList[i].id
								this.from.csid=this.cardList[i].Csid
								break
							}
						}
					}
				}).catch(function (error) {
					console.log(error); 
			})
        },
          //预约
		  order(){
			  console.log(this.from)
                let from=JSON.stringify(this.from)
                let sign=md5(from)
                const params={
                    from:from,
                    sign:sign
                }
                getVs()
                axios.post('/mobileapi/coach/curr.php?act=tk_yy',Qs.stringify(params)).then(data =>{
                    console.log(data.data)
                    let { msg, code,user} = data.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg);
                        } else {
                            window.vant.Toast.success('预约成功')
                            this.timer = setTimeout(this.Timesd, 2000);
                            //this.getlists()
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            },
            Timesd(){
                window.location.href='index.html?vid='+sessionStorage.getItem('vid')+''
            },
			selected(index,id,csid){
                console.log(index)
                this.currIndex=index
                this.from.cid=id
                this.from.csid=csid
            },
    }
})
</script>
</html>